'use strict'

const { Sequelize, DataTypes } = require('sequelize');

//  连接数据库
var sequelize = new Sequelize('qsxiaopangbupangtop', 'postgres', 'xiaopang.1218', {
    host: '8.129.41.113',
    dialect: 'postgres'
});

var fn_createTableAttribute = function (name, attribute) {

    var attributesObj = {};
    // 每个表都有的固定属性id
    attributesObj.id = {
        type: DataTypes.BIGINT,
        primaryKey: true,
        autoIncrement: true
    };
    // 自定义的传入字段
    for (var key in attribute) {
        attributesObj[key] = attribute[key];
    };

    // 每个表都有的固定属性备注
    attributesObj.remark = {
        type: DataTypes.STRING(800),
        defaultValue: '无'
    }
    // 每个表都有的固定属性版本
    attributesObj.version = {
        type :DataTypes.BIGINT,
        defaultValue: 0
    }

    


    // 建表
    var Table = sequelize.define(name, attributesObj);

    return Table;
};

var obj = {
    sequelize,
    DataTypes,
    fn_createTableAttribute
};

module.exports = obj;